<template>
	<view :style="{margin:'80px 50px 0'}">
		<uni-easyinput type="text" placeholder="用户名" v-model="phoneNum"/>
		<uni-easyinput type="text" placeholder="验证码"
		               :style="{marginTop:'10px'}"
		               v-model="code"
		/>
		<button type="primary"
		        @click="getCode"
		        :style="{marginTop:'15px'}">获取验证码
		</button>
		<button type="primary"
		        @click="login"
		        :style="{marginTop:'35px'}">登录
		</button>
	</view>
</template>

<script>
    import Http from "../../utils/http";
    import Toast from "../../components/common/toast";
    import RouteUtil from "../../utils/js/route-util";
    import MD5 from "md5";

    export default {
        name: "Login",

        data() {
            return {
                phoneNum: '',
                code: '123456'
            }
        },

        methods: {
            getCode() {
                const sign = MD5(`account=${this.phoneNum}&400d069a791d51ada8af3e6c2979bcd7`)
                Http.request(Http.getLoginCode,
                    {
                        'account': this.phoneNum,
                        'country_code': "86",
                        sign
                    },
                    (code, msg, info) => {
                        Toast.show(msg)
                    })
            },
            login() {
                Http.request(Http.login, {
                    'user_login': this.phoneNum,
                    'code': this.code,
                    'country_code': "86",
                    'source': "1",
                }, (code, msg, info) => {
                    if (code === 0) {
                        const user=info[0]
                        uni.setStorageSync("user", user)
                        Toast.show("登录成功")
                        RouteUtil.forward(RouteUtil.LIVE_CHOOSE_SDK)
                    } else {
                        Toast.show(msg)
                    }
                })
            },
        }
    }
</script>

<style scoped>

</style>
